package com.pesilo.mvc.view.component.mediator
{
	import com.pesilo.mvc.controller.ApplicationFacade;
	import com.pesilo.mvc.view.component.module.NavigationContainerComponent;
	import com.pesilo.mvc.view.component.module.navigationModule.NavigationComponent;
	
	import flash.events.Event;
	
	import org.puremvc.as3.multicore.interfaces.IMediator;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;

	public class NavigationContainerMediator extends Mediator implements IMediator
	{
		public static const NAME:String="NavigationContainerMediator";
		public function NavigationContainerMediator(viewComponent:Object)
		{
			super(NAME,viewComponent);
		}
		
		override public function onRegister():void{
//			facade.registerMediator(new NavigationMediator(view));
			view.addEventListener(Event.ADDED_TO_STAGE,__viewAddedToStageHandle);
		}
		
		protected function __viewAddedToStageHandle(e:Event):void
		{
			if(facade.retrieveMediator(NavigationMediator.NAME)){
				facade.registerMediator(new NavigationMediator(view.navigationCmp));
			}
		}
		
		override public function listNotificationInterests():Array{
			return[
				ApplicationFacade.SHOW_NAVIGATION_EVENT,
			]
		}
		
		override public function handleNotification(notification:INotification):void{
			var data:Object=notification.getBody();
			
			switch(notification.getName()){
				case ApplicationFacade.SHOW_NAVIGATION_EVENT:
					if(!view.navigationCmp){
						view.navigationCmp=new NavigationComponent();
					}
					view.addChild(view.navigationCmp);
					break;
			}
		}
		
		protected function get view():NavigationContainerComponent{
			return viewComponent as NavigationContainerComponent;
		}
	}
}